/**
 * Created by jocky on 09/10/2017.
 */
var rechargesObj = {
    /**
     *
     * @param type
     * @param direction
     */
    lists: function (type, direction) {
        //显示loading
        show_loading_table('recharge_history_table', 7);

        var params = {};
        params.isRender = 2;//ajax调用

        var pageNo_dom = 'recharge_history_pageNo';
        var pageTotal_dom = 'recharge_history_pageTotal';
        params.pageNo = getPageNo(pageNo_dom, pageTotal_dom, type, direction);

        $.each($('#recharge_history_search_form').find('input,select'), function (i, v) {
            var name = $.trim($(v).attr('name'));
            if (name != '') {
                params[name] = $(v).val();
            }
        });

        $.getJSON('/recharges/lists', params, function (json) {
            $("#" + pageNo_dom).val(parseInt(json.pageNo));
            $("#" + pageTotal_dom).html(parseInt(json.pageTotal));

            var sumMoney = parseFloat(json.sumMoney);
            var tr = "<tr>" +
                "<td><i style='color: red;'>汇总</i></td>" +
                "<td></td>" +
                "<td></td>" +
                "<td></td>" +
                "<td></td>" +
                "<td class='text-right'>" +
                "<i>" + sumMoney.toFixed(2) + "</i>" +
                "</td>" +
                "<td></td>" +
                "</tr>";
            $.each(json.lists, function (i, v) {
                var status;
                switch (parseInt(v.status)) {
                    case 1:
                        status = "<label class='label label-default'>请求中</label>";
                        break;
                    case 2:
                        status = "<label class='label label-success'>成功</label>";
                        break;
                    case 3:
                        status = "<label class='label label-danger'>失败 | " + v.resp_code + "</label>";
                        break;
                    case 4:
                        status = "<label class='label label-default'>已过期</label>";
                        break;
                    default:
                        status = "";
                        break;
                }
                tr += "<tr>";
                tr += "<td><a href='javascript:void(0)' title='查看 / 修改账户信息' onclick=\"traderObj.setForm(" + v.userID + ")\">" + v.loginName + "</a></td>";
                tr += "<td>" + v.accountName + "</td>";
                tr += "<td class='text-center'>" + convertDate(v.pay_start_time, 1) + "</td>";
                tr += "<td class='text-center'>" + (v.type == 1 ? "快捷支付" : "网关支付") + "</td>";
                tr += "<td>" + status + "</td>";
                tr += "<td class='text-right'><i>" + parseFloat(v.money) + "</i></td>";
                tr += "<td></td>";
                tr += "</tr>";
            });

            $("#recharge_history_table>tbody").html(tr);

        })
    },
    setForm:function (recharge_sn) {
        swal({
            title: '是否手动确认本笔充值到账？',
            text: " ",
            type: 'warning',
            showCancelButton: true,
            cancelButtonColor: '#d33',
            cancelButtonText: '取消',
            confirmButtonColor: '#3085d6',
            confirmButtonText: '确定'
        }).then(function () {
            $.getJSON('/recharges/cancel', {recharge_sn: recharge_sn}, function (json) {
                var obj = {
                    title: '操作通知',
                    text: json.msg,
                    styling: 'bootstrap3',
                    delay: 5000,
                    type: ''
                };
                if (json.code == 1) {
                    obj.type = 'info';
                    obj.addclass = 'dark';
                } else {
                    obj.type = 'error';
                }
                new PNotify(obj);

                rechargesObj.lists(3, 0);
            })
        }).catch(swal.noop);
    }
};